package com.hex.ds.hdtp.core.inf.license.activation.repository.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hex.ds.hdtp.core.inf.common.page.Page;
import com.hex.ds.hdtp.core.inf.common.page.converter.IPageAndMyBatisPlusPageConverter;
import com.hex.ds.hdtp.core.inf.license.activation.mapper.IFuncActivationLogMapper;
import com.hex.ds.hdtp.core.inf.license.activation.po.FuncActivationLogPo;
import com.hex.ds.hdtp.core.inf.license.activation.repository.IFuncActivationLogRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class FuncActivationLogRepository implements IFuncActivationLogRepository {

    private final IFuncActivationLogMapper funcActivationLogMapper;

    private final IPageAndMyBatisPlusPageConverter pageConverter;

    @Override
    public Page<FuncActivationLogPo> queryListByPage(FuncActivationLogPo funcActivationLogPo, Page page) {
        final IPage tmpPageResult = funcActivationLogMapper.queryListByPage(
                pageConverter.toMyBatisPlusPage(page)
                , funcActivationLogPo
        );
        final List list = tmpPageResult.getRecords();
        final Page pageResult = pageConverter.toPage(tmpPageResult);
        return pageResult.setData(list);
    }

    @Override
    public FuncActivationLogPo queryById(String pkId) {
        return funcActivationLogMapper.selectById(pkId);
    }

    @Override
    public Integer add(FuncActivationLogPo funcActivationLogPo) {
        return funcActivationLogMapper.insert(funcActivationLogPo);
    }

    @Override
    public Integer modifyById(FuncActivationLogPo funcActivationLogPo) {
        return funcActivationLogMapper.updateById(funcActivationLogPo);
    }

    @Override
    public Integer removeById(String pkId) {
        return funcActivationLogMapper.deleteById(pkId);
    }

    @Override
    public FuncActivationLogPo selectOne() {
        QueryWrapper queryWrapper = new QueryWrapper();
        return funcActivationLogMapper.selectOne(queryWrapper);
    }

    @Override
    public Integer deleteAll() {
        QueryWrapper queryWrapper = new QueryWrapper();
        return funcActivationLogMapper.delete(queryWrapper);
    }

    /**
     * @Method selectActivationStatus
     * @Param
     * @Return java.util.List<java.lang.String>
     * @Description 获取日志表ACTIVATION_STATUS整列数据
     * @Author Yin.Yang
     * @Date 2024/4/8 17:06
     * @Version V1.0
     */
    @Override
    public List<String> selectActivationCodes() {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.select("ACTIVATION_CODE");
        return funcActivationLogMapper.selectObjs(queryWrapper);
    }

}

